package org.chw.callback.services;

import org.chw.callback.config.WechatAPIConfig;
import org.chw.callback.config.WechatConfig;
import org.chw.callback.utils.WechatUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: GetTokenService
 * @Description: 获取微信Token服务
 * @Author: Vincent.Chen
 * @Create: 2018/6/13 10:39
 * @Version: 1.0
 **/
@Service
public class GetTokenService {
    @Autowired
    private WechatConfig wechatConfig;

    @Autowired
    private WechatAPIConfig wechatAPIConfig;

    @Autowired
    private RestTemplate restTemplate;

    /**
     * @return java.lang.String
     * @Author: Vincent.Chen
     * @Description: 调用微信api刷新token
     * @Date: 2018/6/13 11:22
     * @Param: []
     **/
    public String getToken() {
        Map<String, String> paramMap = new HashMap<String, String>();
        paramMap.put("grant_type", "");
        paramMap.put("appid", this.wechatConfig.getAppid());
        paramMap.put("secret", this.wechatConfig.getSecret());
        String URL = WechatUtil.jointURL(this.wechatAPIConfig.getBaseUri(),
                this.wechatAPIConfig.getToken(), paramMap);
        this.restTemplate.getForObject(URL, String.class);
        return null;
    }
}
